#include "Arduino.h"
#include <string>
#include <umm_malloc/umm_malloc.h>
#include <umm_malloc/umm_heap_select.h>

static unsigned long globalLastStatsTime = 0;
static int stateCount = 0;

void stats()
{
    unsigned long now = millis();
    if (now - globalLastStatsTime < 20000)
    {
        return;   
    }

    globalLastStatsTime = now;
    uint32_t free;
    uint32_t max;
    uint8_t frag;
    ESP.getHeapStats(&free, &max, &frag);

    Serial.printf("free: %7u - max: %7u - frag: %3d%% <- ", free, max, frag);
    Serial.println(stateCount++);
}